export interface GetGroupTreeList {
  id: string;
  name: string;
  parent_id: string;
  description: string;
  user_count: number;
  children: GetGroupTreeList[];
  create_time: string;
  system_code: string;
  level: number;
}

export type GroupUserInfoGroup = {
  id: string;
  name: string;
  system_code?: string;
};

export type GroupUserRoles = {
  id: string;
  code: string;
  name: string;
};

export type GroupUserInfoList = {
  id: string;
  name: string;
  user_id: string;
  group: GroupUserInfoGroup;
  status: boolean;
  role: GroupUserRoles;
  create_time: string;
};

export interface GetOrgGroupUserInfoRes {
  total: number;
  list: GroupUserInfoList[];
  offset: number;
  page_size: number;
}

export interface GetOrgGroupUserInfoReq {
  page: number;
  page_size: number;
  searchText: string;
  group_id?: string;
  source?: 'system' | 'auth';
}

export interface CreateUserReq {
  name: string;
  user_id: string;
  group_id?: string;
  password: string;
  role_code: string;
  status: boolean;
}

export interface CreateUserRes {
  id: string;
  name: string;
  user_id: string;
  group: GroupUserInfoGroup;
  status: true;
  roles: GroupUserRoles;
  create_time: string;
}

export interface CreateGroupReq {
  name: string;
  parent_id: string;
  description: string;
}

export interface UpdateGroupReq {
  id: string;
  name: string;
  parent_id: string;
  description: string;
}

export interface TargetUsers {
  id: string;
  name: string;
  user_id: string;
  group: GroupUserInfoGroup;
  create_time: string;
  role: string;
  status: boolean;
  type: string;
}
export interface GetRoleRes {
  id: string;
  code: string;
  name: string;
  description: string;
  target_users?: TargetUsers[] | [];
}
export interface GetRoleResStatementsCondition {
  param: string;
  op: string;
  value: string;
}

export interface DeleteUserReq {
  ids: string[];
}

export interface UpdateUserPasswordReq {
  id: string;
  password: string;
}

export interface UpdateUserInfo {
  name: string;
  user_id: string;
  group_id: string;
  role_code: string;
  status: boolean;
}

export interface ReloRevokeReq {
  app_id: string;
  role_code: string;
  user_ids: string[];
}

export interface ReloAssignReq {
  app_id: string;
  role_code: 'admin' | 'knowledge_manager' | 'knowledge_reviewer';
  user_ids: string[];
}

export interface GetPoliciesResources {
  resource_type: 'dataset' | 'folder' | 'function' | 'database' | '*';
  resource_id: string;
  resource_name: string;
  action: string;
}
export interface GetPoliciesRes {
  target: {
    target_id: string;
    target_name: string;
    target_type: 'user' | 'group';
  };
  resources: GetPoliciesResources[];
}

export interface UpdateRoleCondition {
  param: string;
  op: string;
  value: string;
}
export interface UpdateRoleStatements {
  id: string;
  name: string;
  condition: UpdateRoleCondition[];
}
export interface UpdateRoleReq {
  description: string;
  statements: UpdateRoleStatements[];
}

export interface GetDatasetList {
  agentModel: string;
  avatar: string;
  children: GetDatasetList[];
  inheritPermission: boolean;
  intro: string;
  name: string;
  parent_id: string | null;
  status: string;
  teamId: string;
  tmbId: string;
  type: string;
  updateTime: string;
  vectorModel: string;
  __v: number;
  _id: string;
}

export interface GetDatasetRes {
  total: number;
  list: GetDatasetList[];
}

export interface GetDatasetReq {
  appId: string;
  type?: string;
  searchText?: string;
}

export interface SetPoliciesResources {
  resource_type: string;
  resource_id: string;
  action: string;
}
export interface SetPoliciesStatements {
  target: {
    target_id: string;
    target_type: string;
  };
  resources: SetPoliciesResources[];
}
export interface SetPoliciesReq {
  app_id: string;
  statements: SetPoliciesStatements[];
}

export interface setPoliciesOneReq {
  app_id: string;
  statement: SetPoliciesStatements;
}

export interface SetPoliciesRes {}

export interface PoliciesRevokeReq {
  app_id: string;
  target: {
    target_id: string;
    target_type: string;
  };
}

export type GetRolesBasicReq = {
  code: string;
  name: string;
  count: number;
}[];

export interface GetRolesUserReq {
  offset: number;
  page: number;
  page_size: number;
  app_id: string;
  role_code?: string;
  searchText?: string;
}

export interface GetRolesUserRes {
  total: number;
  list: GetRolesUserList[];
  offset: number;
  page_size: number;
}

export interface GetRolesUserList {
  id: string;
  name: string;
  user_id: string;
  group: GetRolesUserListGroup;
  status: boolean;
  role: GetRolesUserListRole;
  create_time: string;
  status_cn: string;
}

export interface GetRolesUserListGroup {
  id: string;
  name: string;
}

export interface GetRolesUserListRole {
  id: string;
  code: string;
  name: string;
}

export interface GetPoliciesPageRes {
  offset: number;
  page: number;
  page_size: number;
  app_id: string;
  searchText?: string;
}

export interface GetTargetTreeItem {
  target_id: string;
  target_type: string;
  target_name: string;
}

export interface GetTargetTreeReq {
  targets?: GetTargetTreeItem[];
  app_id: string;
}

export interface GetTargetTree {
  target_id: string;
  target_type: string;
  target_name: string;
  user_count: number;
  parent_id: string | null;
  resources: GetTargetTreeResources[];
  childrens: GetTargetTree[];
  level: number;
}

export interface GetTargetTreeResources {
  resource_type: string;
  resource_id: string;
  resource_name: string;
  action: string;
}

export interface GetTargetTreeOriginalTarget {
  target_id: string;
  target_type: string;
  target_name: string;
}

export interface GetTargetTreeRes {
  target_tree: GetTargetTree;
  original_targets: GetTargetTreeOriginalTarget[];
}

export interface SetPoliciesTargetReq {
  app_id: string;
  statement: {
    target: GetTargetTreeOriginalTarget;
    resources: GetTargetTreeResources[];
  };
}

export interface GetDatasetTreeReq {
  appId: string;
  type?: string;
  searchText?: string;
}

export interface GetDatasetTreeItem {
  parent_id: null | string;
  team_id: string;
  tmb_id: string;
  type: string;
  status: string;
  avatar: string;
  name: string;
  vector_model: string;
  agent_model: string;
  intro: string;
  default_permission: number;
  inherit_permission: boolean;
  update_time: string;
  create_time: string;
  metadata: {};
  openapiUrl: string;
  app_id: string;
  groupId: string;
  dataset_tags: [];
  reviewStatus: string;
  groupName: null | string;
  children: GetDatasetTreeItem[];
  targets: GetTargetTreeOriginalTarget[];
  _id: string;
  path: string;
  pathId: string[];
}

export interface GetDatasetTreeRes {
  list: GetDatasetTreeItem[];
}

export interface GetResourceTargets {
  target_id: string;
  target_type: string;
  target_name: string;
}

export interface GetResourceReq {
  app_id: string;
  statement: {
    resource: {
      resource_type: string;
      resource_id: string;
      resource_name: string;
      action: string;
    };
    targets: GetResourceTargets[];
  };
}
